package com.example.storage.service.impl;

import com.example.storage.mapper.StorageTblMapper;
import com.example.storage.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class StorageServiceImpl implements StorageService {

    @Autowired
    StorageTblMapper storageTblMapper;

    /**
     * 扣减库存
     *
     * @param commodityCode 商品编码
     * @param count         数量
     */
    @Transactional // 标注某个方法或类为“事务性” // 声明式事务管理
    @Override
    public void deduct(String commodityCode, int count) {
        storageTblMapper.deduct(commodityCode, count);
        if (count == 5) {
            throw new RuntimeException("库存不足");
        }
    }

}
